package com.jinyu.jyly.net;

import android.os.Handler;
import android.os.HandlerThread;

import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.api.ApiService;
import com.jinyu.jyly.net.api.CTFactory;
import com.jinyu.jyly.net.api.SchedulersCompat;

import java.util.List;

import okhttp3.MultipartBody;
import rx.Observable;


/**
 * Created by Administrator on 2018-04-19.
 * 数据管理类
 */

public class DataManager {

    private ApiService mControlApi;

    private DataManager() {

    }

    public void initService() {
        HandlerThread ioThread = new HandlerThread("IoThread");
        ioThread.start();
        Handler mHandler = new Handler(ioThread.getLooper());
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mControlApi = CTFactory.getControlApi();
            }
        });
    }

    /**
     * 静态内部类的方式,使用单例模式
     */
    public static class DataManagerHolder {
        private final static DataManager INSTANCE = new DataManager();
    }

    /**
     * 公开的方法提供给外部使用
     */
    public static DataManager getInstance() {
        return DataManagerHolder.INSTANCE;
    }

    private String token = "80840ff03980bc534bc4d00cfd640075";

    //获取收获地址列表
    public Observable<AllInfoBean> getAddressList() {
        return mControlApi.getAddressList()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //添加或者修改用户地址
    public Observable<AllInfoBean> getAddOrUpdateAddress(String param) {
        return mControlApi.getAddOrUpdateAddress(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //获取直推用户
    public Observable<AllInfoBean> getChildsList() {
        return mControlApi.getChildsList()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //获取广告
    public Observable<AllInfoBean> getSiteAd(String param) {
        return mControlApi.getSiteAd(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //未登录验证码
    public Observable<AllInfoBean> sendSms(String param) {
        return mControlApi.send_sms(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取公告
    public Observable<AllInfoBean> getGongGaoList(String param) {
        return mControlApi.getGongGaoList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //注册
    public Observable<AllInfoBean> onRegister(String param) {
        return mControlApi.onRegister(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //忘记密码
    public Observable<AllInfoBean> onForgetPsw(String param) {
        return mControlApi.onForgetPsw(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //登录
    public Observable<AllInfoBean> onLogin(String param) {
        return mControlApi.onLogin(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取文章列表
    public Observable<AllInfoBean> getSiteArtices(String param) {
        return mControlApi.getSiteArtices(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //文章详情
    public Observable<AllInfoBean> getArticleDetail(String param) {
        return mControlApi.getArticleDetail(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //获取商品分类
    public Observable<AllInfoBean> getGoodsTypes() {
        return mControlApi.getGoodsTypes()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取商品详情
    public Observable<AllInfoBean> getGoodsList(String param) {
        return mControlApi.getGoodsList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

     //获取商品列表（新接口）
    public Observable<AllInfoBean> getPageGoodsList(String param) {
        return mControlApi.getPageGoodsList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //获取场次时间
    public Observable<AllInfoBean> getTimes() {
        return mControlApi.getTimes()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //获取商品详情
    public Observable<AllInfoBean> getGoodsDetail(String param) {
        return mControlApi.getGoodsDetail(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

 //提交订单
    public Observable<AllInfoBean> addOrder(String param) {
        return mControlApi.addOrder(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //获取个人信息
    public Observable<AllInfoBean> getUserView() {
        return mControlApi.getUserView()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取转账
    public Observable<AllInfoBean> setTransfer(String param) {
        return mControlApi.setTransfer(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //根据手机号获取昵称
    public Observable<AllInfoBean> getNickName(String param) {
        return mControlApi.getNickName(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //提交购买绿色通道
    public Observable<AllInfoBean> addGreen() {
        return mControlApi.addGreen()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //验证身份证
    public Observable<AllInfoBean> authName(String param) {
        return mControlApi.getUserAuth(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //修改昵称
    public Observable<AllInfoBean> setNickName(String param) {
        return mControlApi.setNickName(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //修改手机号
    public Observable<AllInfoBean> changeMobile(String param) {
        return mControlApi.changeMobile(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //登录后发送短信
    public Observable<AllInfoBean> siteMakeSms() {
        return mControlApi.siteMakeSms()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //意见反馈
    public Observable<AllInfoBean> setSuggest(String param) {
        return mControlApi.setSuggest(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //意见反馈列表
    public Observable<AllInfoBean> setSuggestList() {
        return mControlApi.setSuggestList()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //我的订单
    public Observable<AllInfoBean> getOrderList(String param) {
        return mControlApi.getOrderList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

  //我的订单(新接口)
    public Observable<AllInfoBean> getPageOrderList(String param) {
        return mControlApi.getPageOrderList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //获取支付参数
    public Observable<AllInfoBean> getPayMent() {
        return mControlApi.getPayMent()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //提交支付方式
    public Observable<AllInfoBean> setPayMent(String param) {
        return mControlApi.setPayment(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

  //
    public Observable<AllInfoBean> getOrderPayment(String param) {
        return mControlApi.getOrderPayment(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //上传图片
    public Observable<AllInfoBean> updataImg(List<MultipartBody.Part> body) {
        return mControlApi.updataImg(body)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //充值
    public Observable<AllInfoBean> addChong(String param) {
        return mControlApi.addChong(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //提现
    public Observable<AllInfoBean> setRecharge(String param) {
        return mControlApi.setRecharge(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



      //获取充值二维码
    public Observable<AllInfoBean> getChonePayment() {
        return mControlApi.getChonePayment()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //更新订单状态
    public Observable<AllInfoBean> getChangeOrder(String param) {
        return mControlApi.getChangeOrder(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //待转拍
    public Observable<AllInfoBean> setChangeOrder(String param) {
        return mControlApi.setChangeOrder(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //确认收货
    public Observable<AllInfoBean> setChangeShouHuo(String param) {
        return mControlApi.setChangeShouHuo(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //获取系统配置
    public Observable<AllInfoBean> getConfig() {
        return mControlApi.getConfig()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //修改联系人手机号
    public Observable<AllInfoBean> changeContractMobile(String param) {
        return mControlApi.changeContractMobile(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //修改密码
    public Observable<AllInfoBean> changePassword(String param) {
        return mControlApi.changePassword(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取流水
    public Observable<AllInfoBean> getPropertyList(String param) {
        return mControlApi.getPropertyList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //获取绿色通道
    public Observable<AllInfoBean> get_greens() {
        return mControlApi.get_greens()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

 //通知消息
    public Observable<AllInfoBean> getNotice() {
        return mControlApi.getNotice()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //检查是否需要更新app
    public Observable<AllInfoBean> getUpdataApp(String param) {
        return mControlApi.getUpdataApp(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }


    //获取价格
    public Observable<AllInfoBean> getPrice(String param) {
        return mControlApi.getPrice()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //待被买商品
    public Observable<AllInfoBean> getMyGoodList() {
        return mControlApi.getMyGoodList()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

    //待被买商品(新接口)
    public Observable<AllInfoBean> getPageMyGoodList(String param) {
        return mControlApi.getPageMyGoodList(param)
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }



    //新人预排接口
    public Observable<AllInfoBean> setAddNewGreen() {
        return mControlApi.setAddNewGreen()
                .compose(SchedulersCompat.<AllInfoBean>applySchedulers());
    }

}
